home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 7.6 KB | 221 lines | [TEXT/MPS ] |
- // UPopup.h
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UPOPUP__
- #define __UPOPUP__
-
- //----------------------------------------------------------------------------------------
- // Theory of Operation
- // ===================
- //
- // This unit allows Popup menus to be instantiated which are managed by the Popup CDEF,
- // included in System 7.0 and in the installer script for the Communications Toolbox.
- //
- // To use this Unit and the Popup CDEF with MacApp applications that run under System 6.x,
- // the Popup CDEF will need to be included in the application's resource fork.
- //
- // This unit actually extends the capabilities provided by the Popup CDEF as follows:
- // allows for non resource-based MENUs
- // allows for hierarchical popups
- //
- //
- // Usage
- // =====
- //
- // For Sys 6.0 support: include the Popup CDEF in the resource fork of your application
- // with the following lines in your app.r file:
- // include "Popup.rsrc";
- //
- // Also, include either the CMNU or MENU resource in your application's resource fork.
- //
- // To handle the command number associated with the selected item in the popup, include
- // code such as the following in the holding view (e.g. a TDialogView subclass) or in the
- // document (this code was taken from DemoDialogs):
- //
- // void TTestDialogView::DoEvent(EventNumber eventNumber...) // override
- //
- // {
- // if ((eventNumber == mPopupHit) && (source == fMyPopup))
- // {
- // aCommandNumber = ((TPopup*)source)->GetCurrentCommand();
- // switch (aCommandNumber)
- // {
- // case cMyCommand:
- // {
- // }
- // }
- // }
- // }
- //
- // Limitations
- //
- // The first item in the popup can't be a hierarchical menu. This is actually a bug in the
- // Popup CDEF as it exists in System 7.0b1 and earlier versions (including the Comm
- // Toolbox release). A bug report has been filed with SQA.
- //----------------------------------------------------------------------------------------
-
- // MacApp
-
- #ifndef __UCONTROL__
- #include "UControl.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations
- //----------------------------------------------------------------------------------------
-
-
- //----------------------------------------------------------------------------------------
- // Constants
- //----------------------------------------------------------------------------------------
-
- const Boolean kUseAddResMenu = TRUE;
- const Boolean kDontUseAddResMenu = !kUseAddResMenu;
-
-
- //----------------------------------------------------------------------------------------
- // TPopup: supports a simple popup with minimal support for hierarchical popups.
- //----------------------------------------------------------------------------------------
-
- class TPopup : public TCtlMgr // A typical popup menu.
- {
- MA_DECLARE_CLASS;
-
- public:
- TPopup();
- // Empty constructor to satisfy compiler.
-
- void IPopup(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsMenuID, // rsrc ID of 'MENU' or 'CMNU' rsrc
- short itsCurrentItem,
- short itsItemOffset, // width of the popup title area
- short itsStrListID, // popup's title: STR# rsrc id
- short itsIndex, // index into STR#
- /* Style */ short itsStyle, // title's style
- short itsJust, // title's justification
- Boolean useAddResMenu, // true if want to AddResMenu (can use
- // this option iff menuID != kNoResource)
- ResType useAddResMenuResType, // used if useAddResMenu is true
- const TextStyle& itsTextStyle = gSystemStyle);// popup's text style
- // Initializes the popup.
-
- virtual ~TPopup();
-
- virtual unsigned short GetPopupTitleStyle();
- // map fTitleStyle and fTitleJust to popupTitleStyle.
-
- virtual short GetProcID();
- // return the appropriate proc id
-
- virtual void CreateCMgrControl(const CStr255& itsTitle,
- long itsVal,
- long itsMin,
- long itsMax,
- short itsProcID); // override
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFields(TStream* aStream); // override
-
- virtual void WriteFields(TStream* aStream); // override
-
- //------------------------------------------------------------------------------------
- // Imaging
- //------------------------------------------------------------------------------------
-
- virtual Boolean Focus(); // override
-
- virtual void Draw(const VRect& area); // override
- // sets a patch to GetResource in certain cases
-
-
- //------------------------------------------------------------------------------------
- // tracking
- //------------------------------------------------------------------------------------
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis); // override
-
- //------------------------------------------------------------------------------------
- // accessors
- //------------------------------------------------------------------------------------
-
- virtual void AttachMenuRef(MenuRef itsMenuRef);
- // attaches itsMenuRef to this popup
-
- virtual MenuRef GetMenuRef();
- // returns the MenuRef by accessing the control handle's private storage
-
- virtual void GetMenuLabel(CStr255& itsLabel);
- // returns the menu label
-
- virtual CommandNumber GetCurrentCommand();
- // For the currently selected menu item, returns its CommandNumber.
-
- virtual short GetCurrentItem();
- // Returns the value of the current item.
-
- virtual short GetLastItem();
- // Returns the value of the last selected item.
- // For a hierarchical popup menu, this is different than this->GetCurrentItem().
-
- virtual short GetMenuID();
- // Returns the menu ID of the popup.
-
- virtual short GetLastMenuID();
- // Returns the menu id of the last selected menu.
- // For a hierarchical popup menu, this is different than this->GetMenuID().
-
- virtual void GetItemText(short item, CStr255& theText);
- // Returns in "theText" the text for the specified item in the menu.
-
- virtual short GetNumberOfItems();
- // Returns the number of items in the menu.
-
- virtual void GetTitle(CStr255& title);
- // returns the popup's title
-
- virtual void SetCurrentItem(short item, Boolean redraw);
- // Sets the currently selected item, redrawing if required.
-
- virtual void SetPopup(MenuRef itsMenuRef,
- short itsCurrentItem,
- Boolean redraw);
- // Sets the fields of the popup to contain theMenu, with currentItem selected,
- // redrawing if required.
-
- virtual void SetTitle(const CStr255& title);
- // sets the popup's title
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- ResType fUseAddResMenuResType;
- ResNumber fMenuID;
- ResNumber fStrListID; // popup's title: STR# rsrc id
- short fItemOffset;
- short fTitleJust;
- short fUseAddResMenuNumberInitialItems;
- short fIndex; // index into STR#
- Style fTitleStyle;
- Boolean fUseAddResMenu;
- Boolean fMacAppSetDimState;
- };
-
- #endif
-